//
//  UIImage+Extension.swift
//  WeiBo
//
//  Created by zhangyu on 16/10/7.
//  Copyright © 2016年 zhangyu. All rights reserved.
//

import UIKit

extension UIImage {
    //截取当前的window的图片
    static func screenShot() -> UIImage {
        let window = UIApplication.shared.keyWindow!
        //开启图片上下文
        UIGraphicsBeginImageContext(window.size)
//        afterScreenUpdates -> false 表示不需要等待更新后去绘制
        window.drawHierarchy(in: window.bounds, afterScreenUpdates: false)
//        从图片上下文获取图片
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return image!
        
    }
}
